import express from "express";

const app = express();
app.use(express.json());

app.use((req, res, next) => {
    res.header({
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET, OPTIONS, HEAD, PUT, POST",
        "Access-Control-Allow-Headers": "Content-Type,a,token",
    });
    next();
});

app.post("/api/login", (req, res) => {
    const { account } = req.body;
    if (account === "admin1") {
        res.json({
            code: 200,
            data: {
                token: "1",
                nickname: "admin1",
            },
            message: "登录成功",
        });
    } else if (account === "admin2") {
        res.json({
            code: 200,
            data: {
                token: "2",
                nickname: "admin2",
            },
            message: "登录成功",
        });
    } else {
        res.json({ code: 501, message: "登录失败！" });
    }
});
app.listen(8001);
